package com.huaxin.common.jpush;

import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by Administrator on 2017/9/20.
 * 极光推送的一个管理类，主要用于设置别名、标签等
 */

public class JPushManager {
    private static List<NotificationListener> sNotificationListenerList = new ArrayList<>();
    private static List<CustomMsgListener> sCustomMsgListenerList = new ArrayList<>();
    public static void addNotificationListener(NotificationListener listener){
        sNotificationListenerList.add(listener);
    }
    public static void removeNotificationListener(NotificationListener listener){
        sNotificationListenerList.remove(listener);
    }
    public static void addCustomMsgListener(CustomMsgListener listener){
        sCustomMsgListenerList.add(listener);
    }
    public static void removeCustomMsgListener(CustomMsgListener listener){
        sCustomMsgListenerList.remove(listener);
    }
    /**
     * 本地收到了来自服务器推过来的通知消息
     */
    protected static void receivedNotificationMsg(Bundle bundle){
        String title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
        String content = bundle.getString(JPushInterface.EXTRA_ALERT);
        for (NotificationListener listener : sNotificationListenerList) {
            listener.onReceivedNotification(title,content);
        }
    }

    /**
     * 本地收到了来处服务器推过来的自定义消息
     */
    protected static void receivedCustomMsg(Bundle bundle){
        String title = bundle.getString(JPushInterface.EXTRA_TITLE);
        String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
        for (CustomMsgListener listener : sCustomMsgListenerList) {
            listener.onReceivedCustomMsg(title,message);
        }
    }

    /**
     * 用户点击了通知
     */
    protected static void notificationClicked(Bundle bundle){

    }
    public interface NotificationListener{
        void onReceivedNotification(String title,String content);
    }
    public interface CustomMsgListener{
        void onReceivedCustomMsg(String title,String msg);
    }
}
